package week07.springdsrouter;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import week07.springjdbc.Product;
import week07.springjdbc.ProductService;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author edward
 * @since 2021-08-08
 */
public class Main {
    public static void main(String[] args) {
        run("week07.springdsrouter");
    }

    public static void run(String... basePackages) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(basePackages);
        ProductService productService = context.getBean("productService", ProductService.class);
        System.out.println(productService.getProductById("123"));

        Product product = new Product();
        product.setProductName("商品02" + ThreadLocalRandom.current().nextInt(10));
        product.setCategory("衣服");
        product.setQuantity(10_000);
        product.setPrice(BigDecimal.valueOf(39.9));
        product.setCreateDatetime(new Timestamp(System.currentTimeMillis()));
        product.setUpdateDatetime(new Timestamp(System.currentTimeMillis()));
        Product savedProject = productService.addProduct(product);

        System.out.println(productService.getProductById(savedProject.getProductId()));
    }
}
